﻿#pragma once
#include "QCustomPlot/QCustomplot.h"
#include <QWidget>
#include "ui_DefectMap.h"
#include "DefectMapSetting.h"

class DefectMapInfo
{
public:
	QString symbolName = "";	//图例名称
	int symbolType = 0;			//图例类型
	QColor color;
};

class DefectMap : public QWidget
{
	Q_OBJECT

public:
	DefectMap(QWidget *parent = Q_NULLPTR);
	~DefectMap();

private:
	//初始化Map
	void init_customPlot();
	void init_OthersControl();
	void init_DefectMapInfo();
	void reflesh_checkBoxInfo();

private slots:
	//customplot
	void customplot_mousePress(QMouseEvent*);
	void customplot_mouseWheel(QWheelEvent*);
	void customplot_mouseMove(QMouseEvent* e);
	void customplot_mouseRelease(QMouseEvent* e);
	void selectionChanged();
	//图标点击事件
	void customplot_plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent* event);
	//设置CustomPlot样式
	void set_CustomPlot_style();
	//设置CustomPlot Label 样式
	void set_CustomPlotLabel_style();
	//上下限跳转按钮
	void on_pushButton_Jump_clicked();
	//还原
	void on_pushButton_Restore_clicked();
	//弹出设置界面
	void on_pushButton_Setting_clicked();
	//checkBox事件
	void on_checkBox_blemishType_1_stateChanged(int status);
	void on_checkBox_blemishType_2_stateChanged(int status);
	void on_checkBox_blemishType_3_stateChanged(int status);
	void on_checkBox_blemishType_4_stateChanged(int status);

	//增加数据
	void addData(int grapchIndex, double x, double y);
public:
	//设置Y轴上下限
	void setCustomplotRangeY(double lower = 0, double higher = 4000);
	//获取Y轴上下限
	void getCustomplotRangeY(double &lower, double &higher);
	//设置X轴上下限
	void setCustomplotRangeX(double lower = 0, double higher = 7);
	//获取X轴上下限
	void getCustomplotRangeX(double &lower, double &higher);
	//设置背景图
	void setBlackGrounpImage(QString imageFilePath);
	//新增一个图例
	QCPGraph* appendBlemishMapInfo(DefectMapInfo MapInfo );
	//清空一组数据
	void clearData(int grapchIndex);
	//清空所有数据
	void clearAllData();
	//<! 刷新显示
	void refresh();

public:
	void loadCfg(QVector<DefectMapInfo>& infoVec);
	void saveCfg();
signals:
	void userClickPlottable(int graphicsIndex, double X, double Y);
	
private:
	double rangeLower_Y = 0;
	double rangeUpper_Y = 6000;
	double rangeLower_X = 0;
	double rangeUpper_X = 4000;

	double mouseClickLower_Y = 0;
	double mouseClickUpper_Y = 6000;

	double mouseClickLower_X = 0;
	double mouseClickUpper_X = 4000;


	//背景图片路径
	QString mapBackgroundImgFilePath = "";
	//图像
	QPixmap backgroundImg;

	QMenu* m_pMenu;

	QCPItemTracer *tracer;
	QCPItemText *tracerLabel;
	Ui::DefectMap ui;

private:
	QVector<DefectMapInfo> m_blemishMapInfo;

	
};
